public class PSO {
	private AlievPanfilov model;
	private double dt;
	private double duration;
	private double stimulation;
	
	public PSO(){
		this(0.05, 100, 0.5);
	}
	
	public PSO(double dt, double duration, double stimulation){
		model = new AlievPanfilov();
		this.dt = dt;
		this.duration = duration;
		this.stimulation = stimulation;
	}

	public double compute(double mu1, double mu2){
		// Initialisation 
		model.u = 0;
		model.v = 0;
		double t_start = 0;
		double time = 0;
		double previous = 0;		
		model.mu1 = mu1;  
		model.mu2 = mu2;
			
		// Run the model f between the duration
		for(double d = 0; d < duration; d+=dt){
			model.f(time, stimulation);
				
			// We calculate the next value
			model.u = model.u + dt * model.du;
			model.v = model.v + dt * model.dv;
				
				
			if(previous < 0.6 && model.u > 0.6){
				// It's t_start
				t_start = time;	
			}
				
			if(previous > 0.6 && model.u < 0.6){
				break;
			}
				
			// we increase the time
			time += dt;
			
			previous = model.u;
		}
		return time - t_start;
	}
}